﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XuLyDuLieu
{
    public partial class frmKieuChuanHoa : Form
    {
        #region "[class chưa thông tin các Item được hiển thị trên cmb]"
        public class ItemShowCmb {
            public string Name { get; set; }
            public Core.DataProcessing.KieuChuanHoa KieuChuanHoa { get; set; }
            public ItemShowCmb()
            {
                this.Name = "Chuẩn Hóa Mim_Max";
                this.KieuChuanHoa = Core.DataProcessing.KieuChuanHoa.MIN_MAX;
            }
        }
        #endregion

        #region "[phương thức khởi tạo mặc định]"
        public frmKieuChuanHoa()
        {
            InitializeComponent();
        }
        #endregion

        #region "[Không cho người dùng gõ chữ]"
        private void txtGiaTriLonNhat_KeyPress(object sender, KeyPressEventArgs e)
        {
            try {
                if (!char.IsNumber(e.KeyChar) && !char.IsControl(e.KeyChar) && char.IsLetter('.'))
                    e.Handled = true;
            }
            catch { }
        }
        #endregion

        #region "[Load]"
        private void frmKieuChuanHoa_Load(object sender, EventArgs e)
        {
            try {
                ShowItemsInCombobox();
            }
            catch { }
        }
        #endregion

        #region "[Hiển thị thông tin trên combobox]"
        /// <summary>
        /// Hiển thị thông tin trên combobox
        /// </summary>
        private void ShowItemsInCombobox()
        {
            try {
                List<ItemShowCmb> listItems = new List<ItemShowCmb>();
                ItemShowCmb Item1 = new ItemShowCmb();
                Item1.Name = "Chuẩn Hóa Min-Max";
                Item1.KieuChuanHoa = Core.DataProcessing.KieuChuanHoa.MIN_MAX;

                ItemShowCmb Item2 = new ItemShowCmb();
                Item2.Name = "Chuẩn Hóa Z-Score";
                Item2.KieuChuanHoa = Core.DataProcessing.KieuChuanHoa.Z_SCORE;

                listItems.Add(Item1);
                listItems.Add(Item2);

                cmbKieuChuanHoa.DataSource = listItems;
                cmbKieuChuanHoa.DisplayMember = "Name";
                cmbKieuChuanHoa.ValueMember = "KieuChuanHoa";
            }
            catch { }
        }
        #endregion

        #region "[Chọn Ok]"
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                frmMain.m_GiaTriLonNhat = double.Parse(txtGiaTriLonNhat.Text.Trim());
                frmMain.m_GiaTriNhoNhat = double.Parse(txtGiaTriNhoNhat.Text.Trim());
                frmMain.KieuChuanHoa = (Core.DataProcessing.KieuChuanHoa)cmbKieuChuanHoa.SelectedValue;
                this.Close();
            }
            catch { }
        }
        #endregion

        #region "[Chọn cancel]"
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        private void cmbKieuChuanHoa_SelectedIndexChanged(object sender, EventArgs e)
        {
            try {
                if ((XuLyDuLieu.Core.DataProcessing.KieuChuanHoa)cmbKieuChuanHoa.SelectedValue == Core.DataProcessing.KieuChuanHoa.Z_SCORE)
                {
                    txtGiaTriLonNhat.Enabled = txtGiaTriNhoNhat.Enabled = false;
                }
                else
                {
                    txtGiaTriLonNhat.Enabled = txtGiaTriNhoNhat.Enabled = true;
                }
            }
            catch { }
        }
    }
}
